// @file     Test
// @author   Mac Radigan
// @version: $Id: ScriptTool.groovy 43 2011-12-17 20:35:52Z mac.radigan $

package sys.interpreter

import sys.tools.Tool
import org.apache.bsf.BSFManager
import org.apache.bsf.util.IOUtils

public class ScriptTool extends Tool {

  public String getName() {
    return "script"
  }

  public String getDescription() {
    return "runs any script registered with the BSF"
  }

  public String run(String[] args) {
    def ant = new AntBuilder()
    def cli = new CliBuilder(usage: 'tarball -d <directory> [-h]')  
    cli.h(longOpt: 'help',   'show usage information')
    cli.g(longOpt: 'debug',  'turn debugging on')
    cli.f(longOpt: 'file',   'file',  args:1, argName:'file', required:true)
    OptionAccessor opt = cli.parse(args); if(!opt) { return }  
    BSFManager.registerScriptingEngine("groovy", "org.codehaus.groovy.bsf.GroovyEngine", ["groovy", "gy", "g"] as String[])
    //BSFManager.registerScriptingEngine("beanshell", "bsh.util.BeanShellBSFEngine", ["bean", "bsh"] as String[])
    //BSFManager.registerScriptingEngine ("jython", "org.apache.bsf.engines.jython.JythonEngine", ["python", "py"] as String[])
    def manager = new BSFManager()
    def language = manager.getLangFromFilename(opt.f)
    def script = IOUtils.getStringFromReader(new FileReader(opt.f))
    manager.exec(language, opt.f, 0, 0, script)
    return 0
  }

}

/* *EOF* */
